<script setup>
import { ref, onMounted } from 'vue'
import PageContainer from '@/components/PageContainer.vue'
import request from '@/utils/request'
import { ElMessage } from 'element-plus'

const members = ref([])
const loading = ref(false)

const fetchMembers = async () => {
  try {
    loading.value = true
    const { data } = await request.get('/api/family-members')
    members.value = data
  } catch (error) {
    ElMessage.error(error.message || '获取成员列表失败')
  } finally {
    loading.value = false
  }
}

onMounted(() => {
  fetchMembers()
})
</script>

<template>
  <page-container title="家庭成员">
    <el-button type="primary" class="mb-4">
      添加成员
    </el-button>
    
    <el-row :gutter="20">
      <el-col v-for="member in members" :key="member.id" :span="8">
        <el-card class="member-card">
          <template #header>
            <div class="card-header">
              <span>{{ member.nickname }}</span>
              <el-dropdown>
                <el-button link>
                  <el-icon><more /></el-icon>
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item>编辑</el-dropdown-item>
                    <el-dropdown-item>删除</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </template>
          <div class="card-content">
            <el-avatar :size="64" :src="member.avatar" />
            <div class="member-info">
              <p>关系：{{ member.relationship }}</p>
              <p>年龄：{{ member.age }}</p>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </page-container>
</template>

<style scoped>
.mb-4 {
  margin-bottom: 16px;
}

.member-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-content {
  text-align: center;
  padding: 20px 0;
}

.member-info {
  margin-top: 10px;
}

.member-info p {
  margin: 5px 0;
  color: #606266;
}
</style> 